    import 'dart:io';

    const int minTemp = 15;
    const int maxTemp = 30;

    void main() {
      bool lightsOn = false;
      int thermostat = 20;
      bool securityArmed = false;

      while (true) {
        print("\n--- Smart Home Automation ---");
        print("1. Toggle Lights");
        print("2. Set Thermostat");
        print("3. Arm/Disarm Security System");
        print("4. View System Status");
        print("5. Exit");
        stdout.write("Enter your choice: ");
        String? choice = stdin.readLineSync();

        if (choice == "1") {
          lightsOn = !lightsOn;
          print("Lights are now ${lightsOn ? "ON" : "OFF"}");

        } else if (choice == "2") {
          stdout.write("Enter temperature between $minTemp and $maxTemp: ");
          String? tempInput = stdin.readLineSync();
          int? newTemp = int.tryParse(tempInput!);

          if (newTemp != null && newTemp >= minTemp && newTemp <= maxTemp) {
            thermostat = newTemp;
            print("Thermostat set to $thermostat°C");
          } else {
            print("❌ Invalid temperature!");
          }

        } else if (choice == "3") {
          stdout.write("Enter 1 to arm, 0 to disarm: ");
          String? sInput = stdin.readLineSync();

          if (sInput == "1") {
            securityArmed = true;
            print("Security System ARMED");
          } else if (sInput == "0") {
            securityArmed = false;
            print("Security System DISARMED");
          } else {
            print("❌ Invalid input!");
          }

        } else if (choice == "4") {
          String status = securityArmed ? "ARMED" : "DISARMED";
          print("\n--- System Status ---");
          print("Lights: ${lightsOn ? "ON" : "OFF"}");
          print("Thermostat: $thermostat°C");

          if (thermostat % 3 == 0 && thermostat % 5 == 0) {
            print("Perfect Day");
          } else if (thermostat % 3 == 0) {
            print("Cool Day");
          } else if (thermostat % 5 == 0) {
            print("Warm Day");
          }

          print("Security: ${status.toUpperCase()}");

        } else if (choice == "5") {
          print("Exiting Smart Home System...");
          break;
        } else {
          print("❌ Invalid choice!");
        }
      }
    }
